#include "comm.hpp"

int main()
{
    //打开管道文件
    int fd = open(FIFO_NAME, O_WRONLY);
    if(fd < 0){
        std::cerr<<"open fail"<<std::endl;
        return 1;
    }
    
    std::string str;
    while(true){
        std::cout<<"please input: ";
		std::getline(std::cin, str);
        int num = write(fd, str.c_str(), str.size());
        if(num < 0){
            std::cerr<<"write fail"<<std::endl;
            break;
        }
        else if(num == 0){
            std::cout<<"write end"<<std::endl;
            break;
        }
        else{
            std::cout<<"write success"<<std::endl;  
        }
    }

    //关闭管道文件
    close(fd);
	std::cout<<"close success"<<std::endl;
	return 0;

}